<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            padding: 0;
            margin: 0;
        }

        ul {
            margin-top: 0px;
        }

        li {
            text-align: center;
            list-style: none;
            height: 40px;
            width: 400px;
            border: 1px solid rgb(0, 255, 68);
            margin: 0 auto;
            padding-top: 15px;
            margin-top: 0px;



        }

        input {
            margin: 0 auto;
            height: 43px;
            width: 394px;
            margin-left: 579px;
            /* display: inline-block; */
            text-align: center;
            font-size: 40px;
        }
        .on{
            background: brown;
        }
    </style>
</head>

<body>
    <div class="container">
        <input type="text" placeholder='Dom文档对象模型'>
        <ul>
            <li>html</li>
            <li>javascript</li>
            <li>Bom浏览器对象模型</li>
            <li>Dom文档对象模型</li>
        </ul>
    </div>
    <script>
        let ul = document.querySelector('ul');
        let lis = document.querySelectorAll('ul li');
        let input = document.querySelector('input');

        input.onclick=function(){
            ul.style.display='block';
        }

       lis.forEach(function(v) {
           v.onclick=function(){
                              
            //可以写成 (v => v.className='')
            lis.forEach(function(v1){
                v1.className='';
             });     
             
            input.value=this.innerText;
            this.className='on';
            
            ul.style.display='none';
           }
       });
        
    </script>
</body>

</html>